import { defineStore } from 'pinia'

export const useSearchStore = defineStore('search', {
    //状态
    state: () => ({
        search: [],
        show: [
            { _id: '1', name: '铁皮枫斗晶', price: 728, img: 'src/assets/商品.png', desc: "茶叶", num: 1, type: "茶叶", order: 2099021616482512, flag: false, refund: false, shpr: false, favorite: false },
            { _id: '2', name: '阿胶', price: 700, img: 'src/assets/商品.png', desc: "茶叶", num: 2, type: "补品", order: 2099021626482512, flag: false, refund: true, shpr: true, favorite: false },
            { _id: '3', name: '可口可乐', price: 720, img: 'src/assets/商品.png', desc: "茶叶", num: 1, type: "饮料", order: 2099121616482512, flag: true, refund: false, shpr: true, favorite: false },
            { _id: '4', name: '铁皮枫斗晶', price: 718, img: 'src/assets/商品.png', desc: "茶叶", num: 3, type: "茶叶", order: 2099021616482112, flag: false, refund: true, shpr: true, favorite: false },
        ],
        content:{}
    }),
    //方法
    actions: {
        add(value: string) {
            if (this.search.indexOf(value) === -1) {
                if (value !== '') {
                    this.search.push(value)
                }
            }
            // 如果长度超过10，移除最旧的项
            if (this.search.length > 10) {
                this.search.shift();
            }
        },
        //代付款后就是待收货
        changestate(value:string){
            let index = this.show.findIndex(item => item._id === value)
            if(index !== -1){
               this.show[index].flag = true
               this.show[index].shpr = true
            }
        },
        //确认收货
        changeflag(value:string){
            let index = this.show.findIndex(item => item._id === value)
            console.log(index);
            if(index !== -1){
                this.show[index].shpr = true
                this.show[index].refund = true
            }
        },
        //退款内容
        changerefund(value:string){
            let index = this.show.findIndex(item => item._id === value)
            this.content = this.show[index]
        },
        //真正退款
        changerefund2(value:string){
            let index = this.show.findIndex(item => item._id === value)
            if(index !== -1){
                this.show[index].refund = true;
                this.show[index].flag = false;
                this.show[index].shpr = true;
            }
        }
    },
    //计算
    getters: {

    }
})